#pragma once
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <boost/algorithm/string.hpp>
#include "third_lib/to_cppjieba/Jieba.hpp"
#include"Log.hpp"

namespace ns_util
{
    class FileUtil
    {
    public:
        static bool ReadFile(const std::string &file_path, std::string *out)
        {
            std::ifstream in(file_path, std::ios::in); // 以输入方式打开文件
            if (!in.is_open())
            {
                lg(_Fatal,"%s%s%s","ReadFile:",file_path.c_str()," open err!");
                //std::cerr << "ReadFile:" << file_path << " open err!" << std::endl;
                return false;
            }

            std::string line;
            while (std::getline(in, line))
            {
                *out += line;
            }
            in.close();

            return true;
        }
    };
    class StringUtil
    {
    public:
        static void SplitString(const std::string &str, std::vector<std::string> *ret_strs, const std::string &sep)
        {
            boost::split(*ret_strs, str, boost::is_any_of(sep), boost::token_compress_on);
        }
    };

    const char *const DICT_PATH = "./dict/jieba.dict.utf8";
    const char *const HMM_PATH = "./dict/hmm_model.utf8";
    const char *const USER_DICT_PATH = "./dict/user.dict.utf8";
    const char *const IDF_PATH = "./dict/idf.utf8";
    const char *const STOP_WORD_PATH = "./dict/stop_words.utf8";
    class JiebaUtil
    {
    public:
        static void CutString(const std::string &src,std::vector<std::string> *ret)
        {
            _jieba.CutForSearch(src,*ret);
        }
    private:
        static cppjieba::Jieba _jieba;
    };
    cppjieba::Jieba JiebaUtil::_jieba(DICT_PATH,
                                      HMM_PATH,
                                      USER_DICT_PATH,
                                      IDF_PATH,
                                      STOP_WORD_PATH);
}